package project3;

import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class OperatePC {
    public static Scanner in = new Scanner(System.in);

    public static int inputMoreThan1() {
        int i = 0;
        while ((i = in.nextInt()) < 1) {
            System.out.println("输入不合法");
        }
        return i;
    }

    public static void main(String[] args) {
        PC p = new PC("dell G5", 30000);
        int choice = -1;
        while (true) {
            System.out.println("1:格式化，2:安装操作系统，3:启动，4:安装软件，5:下载软件，6:查看各盘情况,9:退出");
            choice = in.nextInt();
            if (choice == 1) {
                if (!p.isStart()) {
                    System.out.println("还没有启动！");
                    continue;
                }
                //格式化
                if (p.isFormat()) {
                    System.out.println("已经格式化！您确定要重新格式化？这样会丢失所有的数据(yes/no)：");
                    String answer = in.next();
                    if (!answer.equals("yes"))
                        continue;
                }
                System.out.println("分成几个盘：");
                int len = inputMoreThan1();
                String panfu[] = new String[len];
                long cap[] = new long[len];
                for (int i = 0; i < len; i++) {
                    System.out.print("请输入第" + (i + 1) + "盘的盘符和大小(M)：");
                    panfu[i] = in.next();
                    cap[i] = inputMoreThan1();
                }
                p.format(len, panfu, cap);
            } else if (choice == 2) {
                System.out.println("win7/win10/win11/xp");
                String osname = in.next();
                System.out.println("size：");
                long size = inputMoreThan1();
                OS os = new OS();
                os.setName(osname);
                os.setSize(size);
                System.out.println("装在哪个盘:");
                String pan = in.next();
                boolean ok = p.install(os, pan);
                System.out.println("安装的结果："+ok);
            } else if (choice == 3) {
                p.start();
            } else if (choice == 4) {
                if(!p.isOsInstalled())
                {
                    System.out.println("操作系统没有装，不能安装其他软件");
                    continue;
                }
                System.out.println("1:普通软件，2：下载软件");
                int type = in.nextInt();
                if (type == 1) {
                    System.out.println("输入名称和大小：");
                    Soft s = new Soft(in.next(), inputMoreThan1());
                    System.out.println("装在哪个盘：");
                    String label = in.next();
                    boolean ok = p.install(s, label);
                    System.out.println(ok?"安装成功":"安装失败");
                } else if (type == 2) {
                    System.out.println("输入名称和大小：");
                    DownloadSoft s = new DownloadSoft();
                    s.setName(in.next());
                    s.setSize(inputMoreThan1());
                    System.out.println("装在哪个盘：");
                    String label = in.next();
                    boolean ok = p.install(s, label);
                    System.out.println(ok?"安装成功":"安装失败");
                } else {
                    System.out.println("没有这个类型！");
                }
            } else if (choice == 5) {

            } else if (choice == 6) {
                p.show();
            }

        }
    }
}
